package com.ruoyi.project.wenyanwen.uuidmapper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.uuidmapper.domain.UuidMapper;
import com.ruoyi.project.wenyanwen.uuidmapper.service.IUuidMapperService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * UUID映射Controller
 * 
 * @author shixiangwen
 * @date 2020-08-13
 */
@Controller
@RequestMapping("/wenyanwen/uuidmapper")
public class UuidMapperController extends BaseController
{
    private String prefix = "wenyanwen/uuidmapper";

    @Autowired
    private IUuidMapperService uuidMapperService;

    @RequiresPermissions("wenyanwen:uuidmapper:view")
    @GetMapping()
    public String uuidmapper()
    {
        return prefix + "/uuidmapper";
    }

    /**
     * 查询UUID映射列表
     */
    @RequiresPermissions("wenyanwen:uuidmapper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UuidMapper uuidMapper)
    {
        startPage();
        List<UuidMapper> list = uuidMapperService.selectUuidMapperList(uuidMapper);
        return getDataTable(list);
    }

    /**
     * 导出UUID映射列表
     */
    @RequiresPermissions("wenyanwen:uuidmapper:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UuidMapper uuidMapper)
    {
        List<UuidMapper> list = uuidMapperService.selectUuidMapperList(uuidMapper);
        ExcelUtil<UuidMapper> util = new ExcelUtil<UuidMapper>(UuidMapper.class);
        return util.exportExcel(list, "uuidmapper");
    }

    /**
     * 新增UUID映射
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存UUID映射
     */
    @RequiresPermissions("wenyanwen:uuidmapper:add")
    @Log(title = "UUID映射", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UuidMapper uuidMapper)
    {
        return toAjax(uuidMapperService.insertUuidMapper(uuidMapper));
    }

    /**
     * 修改UUID映射
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UuidMapper uuidMapper = uuidMapperService.selectUuidMapperById(id);
        mmap.put("uuidMapper", uuidMapper);
        return prefix + "/edit";
    }

    /**
     * 修改保存UUID映射
     */
    @RequiresPermissions("wenyanwen:uuidmapper:edit")
    @Log(title = "UUID映射", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UuidMapper uuidMapper)
    {
        return toAjax(uuidMapperService.updateUuidMapper(uuidMapper));
    }

    /**
     * 删除UUID映射
     */
    @RequiresPermissions("wenyanwen:uuidmapper:remove")
    @Log(title = "UUID映射", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(uuidMapperService.deleteUuidMapperByIds(ids));
    }
}
